package cn.com.zhangwoo.microstar.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import cn.com.microstar.activity.R;
/***
 * 
 * @author Administrator
 *
 */
public class ListSuperMarketAdapter extends BaseAdapter {

	private Context context;
	private String[] array;
	private LayoutInflater inflater;
	TextView text;
	public ListSuperMarketAdapter(Context context,String[] array) {
		// TODO Auto-generated constructor stub
		this.context=context;
		this.inflater=LayoutInflater.from(context);
		this.array=array;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return array.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return array[position];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressLint("ResourceAsColor") @Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (null==convertView) {
			convertView=inflater.inflate(R.layout.item_listview_supermarket, null);
			text=(TextView) convertView.findViewById(R.id.txt_supermarket);
			convertView.setTag(text);
		}
		else
		{
			text=(TextView) convertView.getTag();
		}
		if (position==0) {
			text.setBackgroundColor(R.color.main_color);
		}
	/*	text.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				text.setBackgroundColor(R.color.main_color);
			}
		});*/
		text.setText(array[position]);
		return convertView;
	}
	
	@SuppressLint("ResourceAsColor") public void showOnclickTextBackGround(int postion)
	{
		int aLength=array.length;
		for (int i = 0; i <aLength; i++) {
			if (i==postion) {
				text.setBackgroundColor(R.color.main_color);
			}
			else
			{
				text.setBackgroundColor(R.color.main_color);
			}
		}
	}
	

}
